import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/',
    component: Layout
  },

  {
    path: '/one',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'one',
        component: () => import('@/views/one/index'),
        meta: { title: '第一页', icon: 'one' }
      }
    ]
  },
  {
    path: '/two',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'two',
        component: () => import('@/views/two/index'),
        meta: { title: '第二页', icon: 'two' }
      }
    ]
  }

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
